package com.ioc.importselector;


import com.ioc.color.Yellow;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;

/**
 * @author cyt
 * @create 2020-07-30 上午 12:35
 */
public class BeanDefinitionRegistrar implements ImportBeanDefinitionRegistrar {
    /**
     * @param importingClassMetadata : 当前类上的注解信息
     * @param registry               ： ioc 容器的注册类
     */
    @Override
    public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
        boolean beanDefinition = registry.containsBeanDefinition("com.ioc.color.Red");
        boolean beanDefinition1 = registry.containsBeanDefinition("com.ioc.color.Blue");
        if (beanDefinition && beanDefinition1) {
            RootBeanDefinition rootBeanDefinition = new RootBeanDefinition(Yellow.class);
            registry.registerBeanDefinition("Yellow", rootBeanDefinition);
        }
    }
}
